import { Controller,Inject, Get, Post,Query,Param,Version,Body,Headers, UseInterceptors } from '@nestjs/common';
import { InjectRedis } from '@nestjs-modules/ioredis';
import {CACHE_MANAGER, CacheInterceptor,Cache} from '@nestjs/cache-manager';
// import Redis from 'ioredis';
let a = 1;
@Controller()
// @UseInterceptors(CacheInterceptor)
export class AppController {
  // constructor(@InjectRedis() private readonly redis: Redis) {}
  constructor(@Inject(CACHE_MANAGER) private  cacheManager: Cache){}
  @Get()
  getHello(): string {
    return 'Hello World!';
  }

  @Get()
  @Version('2')
  async getHello2(@Query('token') token): Promise<any> {
    // const res = await this.redis.get('token');
    // // 修改redis的值 token 并且设置过期时间为30天
    // await this.redis.set('token', token||'default token', 'EX', 60 * 60 * 24 * 30);

    const res = await this.cacheManager.get('token');
    await this.cacheManager.set('token', token||'default token');
    return {
      token: res,
    }
  }

  @Post(':id')
  @Version('1')
  async postHello(
    @Query('page') name: string,
    @Param('id') size: string,
    @Body() body: any,
    @Headers('x-tenant-id') tenantId: string,
  ) {}
}
